package shiyanliu;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStreamWriter;
import java.io.EOFException;

public class Test {

    @SuppressWarnings("resource")
    public static void main(String[] args) throws EOFException,FileNotFoundException, IOException, ClassNotFoundException {
        Course course = new Course();
        System.out.println(course.toString());

        Student stu0 = new Student(2020310356,"张三","男   ","汉","计算机");
        Student stu1 = new Student(2020310357,"赵四   ","男   ","回","大数据");
        Student stu2 = new Student(2020310358,"王五   ","女   ","满","物联网");
        Student stu3 = new Student(2020310359,"李六  " ,"男","汉","大数据");
        Teacher tea0 = new Teacher(2000000000,"一老师   ","男   ");
        Teacher tea1 = new Teacher(2000000001,"二老师   ","男   ");
        Teacher tea2 = new Teacher(2000000002,"三老师   ","女   ");
        Course cour0 = new Course(101,"数学 ","111","周一   9:30");
        Course cour1 = new Course(102," 语文 ","222 ","周二  13:30");
        Course cour2 = new Course(103,"java ","0901   ","周三  8:00");
        stu0.addCourse(cour0);
        stu0.addCourse(cour1);
        stu0.addCourse(cour2);
        stu1.addCourse(cour0);
        stu1.addCourse(cour1);
        stu1.addCourse(cour2);
        stu2.addCourse(cour1);
        stu3.addCourse(cour0);
        stu3.addCourse(cour2);
        tea0.addCourse(cour0);
        tea1.addCourse(cour1);
        tea2.addCourse(cour2);

        stu0.removeCourse(cour0);
        stu1.removeCourse(cour2);
        stu1.removeCourse(cour1);
        File f=new File("D:/java6/output.txt");
        FileOutputStream fos1=new FileOutputStream(f);
        OutputStreamWriter dos1=new OutputStreamWriter(fos1);
        String yy = ("选课信息如下：\n"+"学生信息：\n"+stu0.toString()+stu1.toString()+"\n"+stu2.toString()+"\n"+stu3.toString()+
                "\n"+"教师信息：\n"+tea0.toString()+tea1.toString()+tea2.toString()+"\n课程信息：\n"+cour0.toString1()+cour1.toString1()+cour2.toString1());
        dos1.write(yy);
        dos1.close();

        File file1 = new File("D:/java6/Stuoutput.out");
        ObjectOutputStream oout1 = new ObjectOutputStream(new FileOutputStream(file1));
        oout1.writeObject(stu0.toString());
        oout1.writeObject(stu1.toString());
        oout1.writeObject(stu2.toString());
        oout1.writeObject(stu3.toString());
        File file2 = new File("D:/java6/Teaoutput.out");
        ObjectOutputStream oout2 = new ObjectOutputStream(new FileOutputStream(file2));
        oout2.writeObject(tea0.toString());
        oout2.writeObject(tea1.toString());
        oout2.writeObject(tea2.toString());
        File file3 = new File("D:/java6/Couroutput.out");
        ObjectOutputStream oout3 = new ObjectOutputStream(new FileOutputStream(file3));
        oout3.writeObject(cour0.toString1());
        oout3.writeObject(cour1.toString1());
        oout3.writeObject(cour2.toString1());
        oout1.close();
        oout2.close();
        oout3.close();
        ObjectInputStream oinStu = new ObjectInputStream(new FileInputStream("D:/java6/Stuoutput.out"));
        Object Student0 = oinStu.readObject();
        Object Student1 = oinStu.readObject();
        Object Student2 = oinStu.readObject();
        Object Student3 = oinStu.readObject();
        oinStu.close();
        System.out.println("退课操作之前："+Student0);
        System.out.println("退课操作之前："+Student1);
        System.out.println("退课操作之前："+Student2);
        System.out.println("退课操作之前："+Student3);

        ObjectInputStream oinTea = new ObjectInputStream(new FileInputStream("D:/java6/Teaoutput.out"));
        Object newTeacher0 = oinTea.readObject();
        Object newTeacher1 = oinTea.readObject();
        Object newTeacher2 = oinTea.readObject();
        oinTea.close();
        System.out.println(newTeacher0);
        System.out.println(newTeacher1);
        System.out.println(newTeacher2);

        ObjectInputStream oinCour = new ObjectInputStream(new FileInputStream("D:/java6/Couroutput.out"));
        Object newCourse0 = oinCour.readObject();
        Object newCourse1 = oinCour.readObject();
        Object newCourse2 = oinCour.readObject();
        oinCour.close();

        System.out.println("退课操作之前"+newCourse0);
        System.out.println("退课操作之前"+newCourse1);
        System.out.println("退课操作之前"+newCourse2);


        File file01 = new File("D:/java6/Stuoutput'.out");
        ObjectOutputStream oout01 = new ObjectOutputStream(new FileOutputStream(file01));
        stu0.removeCourse(cour0);
        Object Student100=String.valueOf(stu0.toString());
        stu1.removeCourse(cour2);
        stu1.removeCourse(cour1);
        Object Student101=String.valueOf(stu1.toString());
        oout01.writeObject(Student100.toString());
        oout01.writeObject(Student101.toString());
        Object Student102=String.valueOf(stu2.toString());
        System.out.println("退课操作之后："+Student100);
        System.out.println("退课操作之后："+Student101);
        System.out.println("退课操作之后："+Student102);

        File file03 = new File("D:/java6/Couroutput'.out");
        ObjectOutputStream oout03 = new ObjectOutputStream(new FileOutputStream(file03));
        stu0.removeCourse(cour0);
        stu1.removeCourse(cour1);
        stu1.removeCourse(cour2);
        Object Course100=String.valueOf(cour0.toString1());
        Object Course101=String.valueOf(cour1.toString1());
        Object Course102=String.valueOf(cour2.toString1());
        oout03.writeObject(Course100.toString());
        oout03.writeObject(Course101.toString());
        oout03.writeObject(Course102.toString());
        System.out.println("退课操作之后"+Course100);
        System.out.println("退课操作之后"+Course101);
        System.out.println("退课操作之后"+Course102);

    }
}